package com.curlap.orb.util;

import java.lang.reflect.Method;

public class ReflectionUtil 
{
    // getter
    public static boolean isGetter(Method method)
    {
        return (method.getName().startsWith("get") &&
                Character.isUpperCase(method.getName().charAt(3)) &&
                method.getParameterTypes().length == 0 &&
                method.getReturnType() != void.class);
    }
    
    // getter
    public static boolean isSetter(Method method)
    {
        return (method.getName().startsWith("set") && 
                Character.isUpperCase(method.getName().charAt(3)) &&
                method.getParameterTypes().length == 1 && 
                method.getReturnType() == void.class);
    }

    // from getter/setter to field name
    public static String toFieldName(String name)
    {
        StringBuilder builder = new StringBuilder(name.substring(3, 4).toLowerCase());
        builder.append(name.substring(4, name.length()));
        return builder.toString();
    }
}
